import { inBrowser } from '@/utils/base';

export const isDef = (val) => val !== undefined && val !== null;

export const isString = (val) => typeof val === 'string';

export const isFunction = (val) => typeof val === 'function';

export const isObject = (val) => val !== null && typeof val === 'object';

export const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);

export const isDate = (val) =>
  Object.prototype.toString.call(val) === '[object Date]' && !Number.isNaN(val.getTime());

export function isMobilePhone(value) {
  value = value.replace(/[^-|\d]/g, '');
  return /^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9-]{10,13}$/.test(value);
}

export const isNumeric = (val) => typeof val === 'number' || /^\d+(\.\d+)?$/.test(val);

export const isIOS = () =>
  inBrowser ? /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) : false;
